/*  File Name	: SandBoxMonitor.cpp
 *  Author		: Javie Pong
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-10-31
 *  Description:
 */

#include "SandBoxMonitor.h"
#include "Reactor.h"
#include "EpollReactor.h"

SandBoxMonitor::SandBoxMonitor()
{
	this->acceptor_ = NULL;
}

SandBoxMonitor::~SandBoxMonitor()
{
	DELETE(this->acceptor_);
}

SandBoxMonitor* SandBoxMonitor::instance_ = NULL;

SandBoxMonitor *SandBoxMonitor::instance(void)
{
	if(NULL==instance_)
	{
		instance_ = new SandBoxMonitor();
	}
	return instance_;
}

int SandBoxMonitor::init(int line_id,int list_size,int block_size,int pool_size,
		int growth_size,std::string pool_name)
{
	super::init(list_size, block_size, pool_size, growth_size, pool_name);
	this->reactor(Reactor::instance());

	this->acceptor_ = new SandBoxAcceptor(this);
	if(NULL==this->acceptor_)
	{
		return -1;
	}

	if (NULL == this->reactor()->implement())
	{
		this->reactor()->implement(new EpollReactor(10000, 20480));
	}
	return 0;
}

int SandBoxMonitor::start(void)
{
	super::start();

	if(this->acceptor_->open(843,this->reactor())<0)
	{
		return -1;
	}
#ifndef DEBUG

	this->reactor()->run_reactor_loop();
	this->wait_thread_exit();

#endif
	return 0;
}

int SandBoxMonitor::stop(void)
{
	this->reactor()->end_reactor_loop();
	return super::stop();
}

int SandBoxMonitor::run_request_loop(void)
{
	return 0;
}

int SandBoxMonitor::run_respond_loop(void)
{
	return 0;
}

void SandBoxMonitor::collection_info(void)
{

}
